package leetcode.jianzhiOffer;

/**
 * @description: 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * @author: cyy
 **/
public class jz_20220630_05 {

    public static void main(String[] args) {
        System.out.println("result:" + replaceSpace("We are happy."));
    }

    public static String replaceSpace(String s) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char value = s.charAt(i);
            if (value == ' ') {
                buffer.append("%20");
            } else {
                buffer.append(value);
            }
        }
        return buffer.toString();
    }

}
